home *** CD-ROM | disk | FTP | other *** search
- ---FWD_REF.DOC---
-
- Forward References
-
- A86 allows names for a variety of program elements to be forward referenced.
- This means that you may use a symbol in one statement and define it later with
- another statement. For example:
-
- JNZ TARGET
- .
- .
- TARGET:
- ADD AX,10
-
- In this example, a conditional jump is made to TARGET, a label farther down in
- the code. When JNZ TARGET is seen, TARGET is undefined, so this is a forward
- reference.
-
- The only types of symbols that can be forward-referenced are labels (as in the
- above example) and constants. You cannot forward-reference a variable name.
- Hence, you should declare all your variables at the top of your program.
-
- As a general rule, it is best to restrict your forward references to assembler
- directives and jump ahead code, paying particular attention to avoiding them in
- the rest of your instruction statements. This is easily done if you organize
- your source file so that the statements defining variables and constants precede
- your instruction statements. Keep in mind that the fewer guesses the assembler
- has to make, the better job it will do.
-
-
- Forward References in Expressions
-
- Because A86 performs its assembly in just one pass through the source code, the
- uses of forward references are restricted. In particular, forward references
- cannot be used in expression arithmetic. However, there is a trick you can use
- to work your way around almost any case where you might run into this
- restriction. The trick is to move the expression evaluation down in your
- program so that it no longer contains a forward reference; and forward-reference
- the evaluation answer. For example, suppose you have a data-structure that
- begins with its own length. You first try to code it as follows:
-
- D_RECORD:
- DW BEYOND-$
- .
- .
- BEYOND:
-
- You will get an error for the above try because your forward-reference of BEYOND
- appears in the expression BEYOND-$. You can correct this by moving the
- expression evaluation to the end of the table:
-
- D_RECORD:
- DW D_RECORD_LENGTH
- .
- .
- D_RECORD_LENGTH EQU $-D_RECORD
-